<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Stub cache driver, used in testing. Sets and gets instance variables.
 *
 * PHP version 5
 *
 * Copyright 2008 The Picnic PHP Framework
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.

 * @category      Framework
 * @package       Pfw
 * @author        Sean Sitter <sean@picnicphp.com>
 * @copyright     2008 The Picnic PHP Framework
 * @license       http://www.apache.org/licenses/LICENSE-2.0
 * @link          http://www.picnicphp.com
 * @since         0.10
 */

Pfw_Loader::loadClass('Pfw_Cache');

class Pfw_Cache_Stub implements Pfw_Cache
{
    public $options;
    public $data;

    public function __construct ($options = array())
    {
        $this->options = $options;
        $this->data = array();
    }

    /**
     * @see Pfw_Cache#isActive()
     */
    public function isActive()
    {
        return true;
    }
    
    /**
     * @see Pfw_Cache#get()
     */
    public function get($name)
    {
        if (!isset($this->data[$name])) {
            return null;
        }
        return $this->data[$name];
    }
    
    /**
     * @see Pfw_Cache#set()
     */
    public function set($name, $value, $ttl = 300)
    {
        $this->data[$name] = $value;
    }
    
    /**
     * @see Pfw_Cache#add()
     */
    public function add($name, $value, $ttl = 300)
    {
        $this->data[$name] = $value;
    }
    
    /**
     * @see Pfw_Cache#delete()
     */
    public function delete($name)
    {
        if (isset($this->data[$name])) {
            unset($this->data[$name]);
        }
    }
}
